package com.foreknow.view;

import com.foreknow.model.Business;
import com.foreknow.service.BusinessService;
import com.foreknow.service.impl.BusinessServiceImpl;

import java.awt.*;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class GetQueryById extends JFrame {


    private JPanel contentPane;
    private  JTextField textField;
    private JTable table;
    static private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    GetQueryById frame = new GetQueryById();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public GetQueryById() {

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 732, 427);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JLabel lblNewLabel = new JLabel("\u8BF7\u8F93\u5165\u8981\u67E5\u8BE2\u7684id\uFF1A");
        lblNewLabel.setFont(new Font("宋体", Font.BOLD, 20));
        lblNewLabel.setBounds(69, 113, 195, 41);
        contentPane.add(lblNewLabel);

        textField = new JTextField();
        textField.setBounds(306, 120, 218, 31);
        contentPane.add(textField);
        textField.setColumns(10);
        JButton btnNewButton = new JButton("\u67E5\u8BE2");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
//                String text = textField.getText();
//                int id = Integer.parseInt(text);
//                BusinessService businessService=new BusinessServiceImpl();
//                Object b =businessService.getQueryById(id);
//               Business b1= (Business) b;
//                business[0][0]=b1.getBusinessId()+"";
//                business[0][1]=b1.getPassword();
//                business[0][2]=b1.getBusinessName();
//                business[0][3]=b1.getBusinessAddress();
//                business[0][4]=b1.getBusinessExplain();
//                business[0][5]=b1.getStarPrice()+"";
//                business[0][6]=b1.getDeliveryPrice()+"";
////                GetQueryById.this.validate();
//                table.updateUI();
//                System.out.println("查询");
//                contentPane.updateUI();
////                GetQueryById getQueryById=new GetQueryById();
                String text = textField.getText();
                setId(text);
                ShowGetById showGetById=new ShowGetById();
                showGetById.setVisible(true);
                GetQueryById.this.dispose();

            }
        });
        btnNewButton.setBounds(545, 122, 113, 27);
        contentPane.add(btnNewButton);

        JButton btnNewButton_1 = new JButton("\u53D6\u6D88");
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MainWindow mainWindow = new MainWindow();
                mainWindow.setVisible(true);
                GetQueryById.this.dispose();
            }
        });
        btnNewButton_1.setBounds(306, 299, 113, 27);
        contentPane.add(btnNewButton_1);


////        String text = textField.getText();
////        int id = Integer.parseInt(text);
//        BusinessService businessService=new BusinessServiceImpl();
//        Object b =businessService.getQueryById(1002);
//        Business b1= (Business) b;
//        business[0][0]=b1.getBusinessId()+"";
//        business[0][1]=b1.getPassword();
//        business[0][2]=b1.getBusinessName();
//        business[0][3]=b1.getBusinessAddress();
//        business[0][4]=b1.getBusinessExplain();
//        business[0][5]=b1.getStarPrice()+"";
//        business[0][6]=b1.getDeliveryPrice()+"";

        table= new JTable();
        table.setModel(new DefaultTableModel(
//               business,
                new Object[][] {
                        {null, null, null, null, null, null, null},
                },
                new String[] {
                        "New column", "New column", "New column", "New column", "New column", "New column", "New column"
                }
        ));
        table.getColumnModel().getColumn(0).setPreferredWidth(90);
        table.getColumnModel().getColumn(0).setMinWidth(20);
        table.getColumnModel().getColumn(1).setPreferredWidth(90);
        table.getColumnModel().getColumn(1).setMinWidth(20);
        table.getColumnModel().getColumn(2).setPreferredWidth(90);
        table.getColumnModel().getColumn(2).setMinWidth(20);
        table.getColumnModel().getColumn(3).setPreferredWidth(90);
        table.getColumnModel().getColumn(3).setMinWidth(20);
        table.getColumnModel().getColumn(4).setPreferredWidth(90);
        table.getColumnModel().getColumn(4).setMinWidth(20);
        table.getColumnModel().getColumn(5).setPreferredWidth(90);
        table.getColumnModel().getColumn(5).setMinWidth(20);
        table.getColumnModel().getColumn(6).setPreferredWidth(90);
        table.getColumnModel().getColumn(6).setMinWidth(20);
        table.setBounds(107, 182, 521, 85);
        contentPane.add(table);
    }
}